package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.AuthTreeGetButtonVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.AuthTreeButtonVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.AuthTreeMenuButtonCheckIdVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.AuthTreeMenuVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.*;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.MemberRoleGetButtonVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.PlatformMemberRoleGetVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.PlatformMemberRoleQueryVO;
import com.ssy.lingxi.member.merchant.service.web.IPlatformMemberRoleService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 平台后台-权限管理-角色管理
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-30
 */
@RestController
@RequestMapping("/member/manage/role")
public class PlatformMemberRoleController {
    @Resource
    private IPlatformMemberRoleService platformMemberRoleService;

    /**
     * 分页、模糊查询会员角色
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformMemberRoleQueryVO>> pageMemberRole(@RequestHeader HttpHeaders headers, @Valid MemberRolePageVO pageVO) {
        return platformMemberRoleService.pageMemberRole(headers, pageVO);
    }

    /**
     * 获取左侧权限菜单列表，以树形菜单形式返回
     * @param headers HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/auth/tree", method = RequestMethod.GET)
    public Wrapper<List<AuthTreeMenuVO>> treeMemberAuth(@RequestHeader HttpHeaders headers) {
        return platformMemberRoleService.treeMemberAuth(headers);
    }

    /**
     * 根据左侧菜单Id，查询右侧按钮列表
     * @param headers HttpHeaders信息
     * @param buttonVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/auth/button", method = RequestMethod.GET)
    public Wrapper<List<AuthTreeButtonVO>> getMemberAuthButtons(@RequestHeader HttpHeaders headers, @Valid AuthTreeGetButtonVO buttonVO) {
        return platformMemberRoleService.getMemberAuthButtons(headers, buttonVO);
    }

    /**
     * 新增会员角色
     * @param headers  HttpHeaders信息
     * @param addVO 接口参数
     * @return 新增结果
     */
    @RequestMapping("/add")
    public Wrapper<Void> addMemberRole(@RequestHeader HttpHeaders headers,@RequestBody @Valid PlatformMemberRoleAddVO addVO) {
        return platformMemberRoleService.addMemberRole(headers, addVO);
    }

    /**
     * 查询单个会员角色的信息
     * @param headers  HttpHeaders信息
     * @param idVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public Wrapper<PlatformMemberRoleGetVO> getMemberRoleAuth(@RequestHeader HttpHeaders headers, @Valid MemberRoleIdVO idVO) {
        return platformMemberRoleService.getMemberRole(headers, idVO);
    }

    /**
     * 查询左侧树形权限菜单中勾选的Id列表
     * @param headers HttpHeaders信息
     * @param idVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/auth/tree/check", method = RequestMethod.GET)
    public Wrapper<AuthTreeMenuButtonCheckIdVO> getTreeCheckIds(@RequestHeader HttpHeaders headers, @Valid MemberRoleIdVO idVO) {
        return platformMemberRoleService.getTreeCheckIds(headers, idVO);
    }

    /**
     * 查询右侧勾选的按钮Id列表
     * @param headers HttpHeaders信息
     * @param buttonVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/auth/button/check", method = RequestMethod.GET)
    public Wrapper<MemberRoleGetButtonVO> getButtonCheckIds(@RequestHeader HttpHeaders headers, MemberRoleButtonVO buttonVO) {
        return platformMemberRoleService.getButtonCheckIds(headers, buttonVO);
    }

    /**
     * 更新会员角色及左侧菜单权限
     * @param headers  HttpHeaders信息
     * @param updateVO 接口参数
     * @return 更新结果
     */
    @RequestMapping("/update")
    public Wrapper<Void> updateMemberRole(@RequestHeader HttpHeaders headers, @RequestBody @Valid PlatformMemberRoleUpdateVO updateVO) {
        return platformMemberRoleService.updateMemberRole(headers, updateVO);
    }

    /**
     * 新增或更新会员角色菜单关联按钮
     * @param headers HttpHeaders信息
     * @param upsertVO 接口参数
     * @return 新增或更新结果
     */
    @RequestMapping("/button/upsert")
    public Wrapper<Void> updateMemberRoleButton(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberRoleUpdateButtonVO upsertVO) {
        return platformMemberRoleService.updateMemberRoleButton(headers, upsertVO);
    }

    /**
     * 删除会员角色
     * @param headers  HttpHeaders信息
     * @param idVO 接口参数
     * @return 删除结果
     */
    @RequestMapping("/delete")
    public Wrapper<Void> deleteMemberRole(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberRoleIdVO idVO) {
        return platformMemberRoleService.deleteMemberRole(headers, idVO);
    }

    /**
     * 更新会员角色状态
     * @param headers HttpHeaders信息
     * @param statusVO 接口参数
     * @return 更新结果
     */
    @RequestMapping("/updatestatus")
    public Wrapper<Void> updateMemberRoleStatus(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberRoleUpdateStatusVO statusVO) {
        return platformMemberRoleService.updateMemberRoleStatus(headers, statusVO);
    }
}
